/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pokemon.services;

import com.pokemon.dao.StadiumDAO;
import com.pokemon.dto.DTOConvertor;
import com.pokemon.dto.StadiumDTO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Ladislav
 */
@Service("stadiumManager")
@Transactional
public class StadiumServiceImpl implements StadiumService{
   
    @Autowired
    private StadiumDAO stadiumDAO;
   
    @Required
    @Autowired
    public void setStadiumDAO(StadiumDAO stadiumDAO)
    {
        this.stadiumDAO = stadiumDAO;
    }

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @Transactional
    public StadiumDTO addStadium(StadiumDTO stadium) {
        stadiumDAO.addStadium(DTOConvertor.dtoToEntity(stadium));
        return stadium;
    }

    @Transactional
    public StadiumDTO getStadium(Long id) {
        return DTOConvertor.entityToDto(stadiumDAO.getStadium(id));
    }

    @Transactional
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public StadiumDTO updateStadium(StadiumDTO stadium) {
        stadiumDAO.updateStadium(DTOConvertor.dtoToEntity(stadium));
        return stadium;
    }

    @Transactional
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public StadiumDTO removeStadium(StadiumDTO stadium) {
        stadiumDAO.removeStadium(DTOConvertor.dtoToEntity(stadium));
        return stadium;
    }
   
    @Transactional
    @Override
    public List<StadiumDTO> getAllStadiums() {
        return DTOConvertor.stadiumEntityListToDtoList(stadiumDAO.getAllStadiums());
    }
}
